GBML manual / Using the editor

Behaviors

Draw how an enemy or a character acts as boxes and arrows - patrol, see the player, chase, attack - start from a ready-made one, and call it from the object's Step event.

What it is

A behavior says what a character does, and when it changes what it is doing. A guard might patrol, then chase you when it sees you, then attack when it touches you, then go back when you get away.

You draw that. Each thing the guard can be doing is a state, shown as a box. An arrow from one box to another says when it changes. Gbabel writes a script that does it, and you can still read the script.

The designer lives in the Code tab, in a section called Behaviors, under HUD & Menus.

Make one

  1. Click + Behavior in the section.
  2. Type a name, like guard.
  3. Pick a ready-made behavior to start from, or Start empty. The ready-made ones are sorted into genres you can fold and unfold: Top-down (patrol guard, chaser, wanderer, shooter that keeps its distance, coward that runs away when hurt), Platformer (walker that turns at ledges and walls, jumper, flyer that swoops, boss with two phases), Shooter (wave flyer, turret, homing enemy) and Puzzle and RPG (villager, follower, block that slides). One that fits two genres is in both. Gbabel fills in the player, the shot, the path, the sound and the animations from your project. Anything it cannot find is left empty, and Things to fix tells you what to pick.
  4. Two windows open: the designer, with the picture, and a Properties window beside it for the box or arrow you picked.

Click a name in the list to open it again. Right-click it to rename, duplicate, show the script or delete it.

Use it on an object

A behavior is used by being called from an object's Step event:

guard();

Each object that does this has its own place in the states. Ten guards can share one behavior, and each one is patrolling, chasing or attacking on its own.

To get an object ready, pick it in Used by under Use in an object. Gbabel then does two things for you:

To stop an object using the behavior, press Remove beside it in Used by. Gbabel takes out the lines it added to the Create event and the guard(); line of the Step event, and leaves everything else you wrote there. You can undo it.

You can also type guard(); in a Step event yourself. Then Things to fix tells you the object still needs its numbers, and Set up does it.

The designer window

Moving around the picture

It works like the other pictures in Gbabel.

Boxes and arrows

Groups

+ Group makes a bigger box that holds states that belong together, like Combat with Approach, Attack and Recover inside it. Drop a state into the box and it becomes part of the group; drag it out and it is out again. Moving the group by its title moves the states with it.

Arrows from any state

Any state shows a special box. An arrow drawn from it is taken from every state, like "hp is at or below 0, then go to dead". Each such arrow says whether it is looked at before the state's own arrows or after them. It never fires in the state it points at. To keep a state out of reach of every such arrow (a defeated enemy that a late hit must not bring back to life), tick Ignore arrows from any state in that state's Properties; its own arrows still work.

A state

A state has three lists of actions.

ListWhen it happens
When it entersOnce, when it moves into this state.
Every frame it is hereEvery frame while it is in this state.
When it leavesOnce, when it moves out of this state.

A state can also name an animation. It plays when the state is entered (with Start over if you want it from the first picture again), before the state's own When it enters actions. The animation is picked from the animations of the objects that use the behavior.

Pictures by direction

For a game seen from above, open Pictures by direction in the state's details (it starts closed). The Animation above is the picture for facing down. Up and Sideways are the pictures for those two ways, and a way left empty plays the Animation above, so a state that has none of them works as before.

The list of actions

Each action is a card. Pick one from Add an action; the box groups them by what they do (Moving, Looks, Sound, Objects, Variables, Choices, The world), and each list only offers the actions that make sense there. Where your project has the things, you pick from a list: objects, paths, sounds, sprites, particle effects, sprite effects, animations and scripts.

ActionWhat it does
Stand stillStops moving.
Move toward / away from somethingWalks toward (or away from) the nearest one of an object, and slides along walls.
Move in a directionWalks one of 8 directions, or an angle, every frame.
Keep a distance from somethingCloser when it is too far, back off when it is too near.
Circle around somethingWalks round the nearest one of an object at about the same distance.
Dash toward somethingA short fast burst when the state starts, then it stops.
JumpFor a side-view game: jumps only when there is solid ground under its feet. It needs gravity to come back down.
Bounce off wallsWalks one way and turns back at something solid, and at ledges if you tick it. A game where every Player movement is top-down has no ground to end, so the ledge turning is left out there.
Go back to where it startedWalks home and stops there.
Jump to a spot or to somethingAppears at once at a spot, or on the nearest one of an object.
Follow a pathWalks along a path from the Paths tab. In Every frame it starts once, when the state starts, and keeps going. It stops following when the state is left.
Stop following the pathStops where it is.
Walk between two pointsWalks back and forth between two spots in the room.
WanderWalks in a random direction and picks a new one every so often.
Face somethingTurns its direction toward the nearest one of an object, so a shot made here goes that way.
Face left or right toward somethingMirrors the picture so it looks at the nearest one of an object.
Change the pictureShows a different sprite.
Play an animationPlays one of the object's animations, picked from a list.
BlinkFlashes on and off for a number of frames after the state starts.
Hide or show itselfMakes the picture disappear, or come back.
Play a sprite effect / Stop the sprite effectStarts (or ends) an effect from the Overlay Effects tab on this object only, like a hit flash.
Play a soundPlays a sound once.
Shake the screenShakes the camera for a moment.
Burst of particlesSets off a particle effect at its own spot.
Make an objectMakes a new object, like a shot. In Every frame it makes one every so many frames, and it can aim it at something.
Destroy itselfRemoves this object from the room.
Set an alarmStarts one of the 12 alarms counting down.
Change a variable of another objectThe one it touches, or the nearest one of an object: take 1 from the player's hp.
Tell another object somethingSends a word to the nearest one of an object, or to all of them.
Change a variableSets a variable, or adds to it or takes from it, or sets it to a random number. The variable can be the object's, the whole game's, or this behavior's own.
Run a scriptRuns one of your own scripts and hands it numbers.
Run a line of codeOne line of GBML for anything not on this list. The compiler checks it and Things to fix shows what it says.
Wait a bit, then do the restThe actions under it only start after the state has lasted that long.
If ... then ... otherwiseDoes some cards when something is true and others when it is not. It uses the same conditions as an arrow and can hold other Ifs.
RepeatDoes the cards inside this many times in a row.
Pick one at randomPicks ONE of its choices by chance. A choice with a bigger weight is picked more often.

Variables

+ Variable gives the behavior something to remember for each object that uses it: a number, a yes or no, or a stopwatch that counts the frames by itself. Actions and conditions can set it, add to it and compare it. A state can count how often it comes in by adding 1 to one of your number variables each time.

An arrow

An arrow has conditions. It is taken when all of them hold, or when any one of them holds, as you choose (the choice appears when there are two or more). Every condition has a not button that turns it round, and a group condition holds other conditions. An arrow with no conditions is taken at once.

ConditionIt holds when
Something is close or farThe nearest one of an object is within, or farther than, a number of pixels.
It can see somethingThe nearest one of an object is within a number of pixels and nothing solid is in the way. You can name an object, like a wall, that also blocks the view.
It has been here a whileThe state has lasted this many frames.
A variable compares with a numberLike hp is at or below 3.
A buttonA button was pressed, or is held down.
It is touching somethingIt overlaps the nearest one of an object.
Its path has endedIt was following a path that stops at the end, and it got there.
A random chance each frameHappens by luck. 2 means about once every 50 frames.
Its animation has finishedA play-once animation reached its last picture (you can name which).
Its animation is on a pictureThe animation is on, or past, a picture.
An animation event happenedA picture with this event name (from the Animations window) was just shown.
Its attack hits somethingThe attack boxes of its animation touch the body boxes of an object.
It is standing on somethingFor a side-view game: there is solid ground under its feet.
It is off the screenIt is outside what the camera shows.
How many of an object existCompares the number of an object in the room with a number.
A variable of another object comparesLooks at a variable of the nearest one of an object.
It was told somethingAnother object sent it this word. It counts for one frame only.

Which arrow first?

Every frame the arrows out of the state are looked at in order, and the first one whose conditions hold is taken. So the order is the priority. The list in Properties shows the order. ▲ and ▼ move an arrow. Arrows from Any state come before the state's own arrows or after them, as each one says.

Give several arrows out of one state a chance weight (anything above 0) and, of those that hold at the same moment, one is picked by chance, in proportion to the weights: 3 is picked three times as often as 1.

When an arrow is taken, the old state's When it leaves actions run once, the new state starts counting from 0, and its When it enters actions run once. The new state's Every frame actions begin on the next frame, so one frame never passes through two states.

An example: a guard

  1. patrol: When it enters: follow the path path_guard. Every frame: nothing.
  2. chase: When it enters: play a sound. Every frame: move toward obj_player at 1.2.
  3. attack: Every frame: stand still, and make an obj_shot every 30 frames, aimed at obj_player.
  4. return: Every frame: walk between two points.

Arrows, in this order:

Pick obj_guard in Use in an object and play.

A bigger example: a boss

This is the Boss with two phases ready-made behavior, drawn with groups and an arrow from any state.

To follow the boss while it plays, open it in the Inspector of the Play tab: the variable boss_state shows the name of the state, and that box lights up in the designer.

An attack pattern: a warning, a strike and a chance to hit back

A boss's attacks are about timing: how long the warning shows, when the strike lands, how long the boss can be hurt afterward. You could tune that with timers and Wait cards, but a pattern puts it on a timeline you can read.

Pick a state and open Attack pattern in its details. It is a strip of steps, each one a section you can open for its settings:

Times are in frames: 60 frames are one second. Under the steps, a bar shows the timing, and Play this pattern runs a cursor over it so you can see the rhythm without building the game.

Where it happens. A step that aims asks Aim at: the player (the nearest one of the object you pick, or The player: any object that uses a Player movement), NEAR the player (a random spot within so many pixels, and never right on them), a fixed spot, a random spot in the room, or the spot the last step aimed at, so the strike lands exactly where the warning was shown.

Fair play. When you add an Attack, Gbabel adds an Open a hit window step after it, so the player is rewarded for dodging. While the window is open the behavior's yes-or-no variable hit_window is yes (the boss's own variable is <behavior>_hit_window); check it where your boss takes damage. Things to fix tells you when an attack has no window after it.

Phases. Open Phases in the details to group states by health. Pick the variable that is the boss's health and its full value, then + Add a phase: it starts when the health is at or below a percent, its states run its patterns faster (1.3 is a third faster) and every Repeat can repeat more times. A state joins a phase with Phase in its details. When the health drops, a state of an earlier phase goes to the first state of the phase. To make a phase's version of an attack, duplicate the state and give the copy the phase.

Hurt bosses flicker. Under Attack pattern, pick the boss's health variable and a Harmless for time (about 2 seconds to begin with; 0 turns it off). When the health drops, the boss flickers: its attacks and its Change a variable of another object cards hurt nobody, no hit window opens, and the variable <behavior>_harmless counts the frames left. Check it where your boss takes damage: above 0 means do not hurt it.

Hit box. An Attack that makes or shoots an object has a Hit box: 75 percent of the object's picture to begin with, so a near miss is a miss. 100 leaves the box as the object has it.

A design that has no patterns writes the same script it always did. A pattern is ordinary behavior code, so it works on every console that does the behaviors.

The script belongs to the designer

The script is read-only in the code editor, because it is written again every time you change the design. At the top of its window you see Made by the behavior designer and two buttons: Open in designer, and Make it my own script. The second one copies the script into a new, ordinary script that you can edit. The copy is no longer connected to the designer, and it keeps using the same numbers.

Rename, delete and saving

Good to know

See also: The Code tabScriptsHUD and menusinstance_nearestdist_tomove_slidepath_startcollision_linetile_solidroll_chanceanimation_playattack_touching